package per.jdz.retryer.demo;

import java.util.concurrent.TimeUnit;
import java.util.function.Predicate;

import per.jdz.retryer.core.Retryer;
import per.jdz.retryer.core.RetryerBuilder;
import per.jdz.retryer.predicate.Predicates;
import per.jdz.retryer.strategy.TimeRetryerStrategy;

public class Main {
    static volatile Boolean flag = true;

    public static void main(String[] args) {
        final Retryer retryer = RetryerBuilder.newBuilder()
                .withRetryerStrategy(new TimeRetryerStrategy(3, 1, TimeUnit.SECONDS))
                .retryerIfResult(Predicates.equalTo(true))
                .retryerLister(retryerStrategy -> {
                    System.out.println("hello-monitor");
                })
                .build();
        new Thread(() -> {
            try {
                Thread.sleep(1000l);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            flag = false;
            // System.out.println(flag);
        }).start();
        retryer.exec(() -> {
            System.out.println("hello jdz-retry");
            System.out.println(flag);
            return flag;
        });
    }
}
